$(document).ready(function(){
    // username login_pwd login_pwd_repeat deal_pwd deal_pwd_repeat captcha
    // var $iosDialog1 = $('#iosDialog1');
    $('#logout').on('click', function(){
        $('#dialogs').on('click', '.cancle', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('#iosDialog1').fadeIn(200);
    });
    $('#avatar').on('click', function(){
        $("#avatar_input").click();
    });
    $("#confim_logout").on('click', function() {
        out();
        // 界面跳转
        // jump('xxx');
    })
});

// 登陆的ajax
function out(data) {
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Login/logout/" ,//url
        data: {'data':'logout'},
        success: function (result) {
            if (result.code == 1) {
                window.location.href='/index.php/Home/Login/index';
            }else{
                notify('退出失败');
            }
        },
        error : function() {
            notify("异常！");
        }
    });
}


function update_avatar(val) {
    var formData = new FormData();
    var avatar = document.getElementById("avatar_input");
    var fileObj = avatar.files[0];
    formData.append('avatar',fileObj);
    // console.log(file);
     $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/avatar/" ,//url
        processData: false,
        contentType: false,
        async:false,
        data: formData,
        success: function (result) {
            if (result.status == 1) {
            $("#avatar_img").attr("src",result.filename);
            }else{
                notify(result.info);
            }
            // todo 替换真实url
        },
        error : function() {
            notify("异常！");
        }
    });
}
